import request, { type ListQuery, type ListResponse } from "@/utils/request";

const BASE_URL = "/api";

export const MerchantAgentApi = {
  getMerchantAgentList: (params: ListQuery) => {
    return request.get<any, ListResponse<MerchantAgentItemType>>(`${BASE_URL}/merchtants/agent/`, {
      params,
    });
  },
  getMerchantAgentTransactionList: (params: ListQuery) => {
    return request.get<any, ListResponse<MerchantAgentTransactionListItem>>(
      `${BASE_URL}/sales/agent/merchant/`,
      {
        params,
      }
    );
  },
};

export type MerchantAgentListQuery = {} & ListQuery;

export type MerchantAgentTransactionListQuery = {
  merchant?: number | "all";
  status?: OrderStatusType | "all";
} & ListQuery;

export type MerchantAgentItemType = {
  id: number;
  agent_commission: number;
  name: string;
  contact_name: string;
  contact_phone: string;
  contact_email: string;
  is_active: boolean;
  agent: number;
  user: number;
};

/**
 * @description 订单状态
 * @property {string} pending 待支付
 * @property {string} paid 已支付
 * @property {string} express 已发货
 * @property {string} completed 已完成
 * @property {string} canceled 已取消
 *
 */
export type OrderStatusType = "pending" | "paid" | "express" | "completed" | "canceled";

export type MerchantAgentTransactionListItemLine = {
  id: number;
  product: any;
  variant: any;
  uom: any;
  created_at: string;
  updated_at: string;
  is_active: boolean;
  name: string;
  barcode: string;
  quantity: number;
  stand_price: string;
  unit_price: string;
  subtotal_price: string;
  subtotal_stand_price: string;
  product_attributes: any[];
  order: number;
};

export type MerchantAgentTransactionListItem = {
  id: 124;
  supplier: {
    id: number;
    name: string;
  };
  merchant: {
    id: number;
    name: string;
  };
  lines: [];
  created_at: string;
  updated_at: string;
  is_active: boolean;
  code: string;
  origin: null;
  status: OrderStatusType;
  total_price: string;
  total_stand_price: string;
  payment_amount: string;
  express_amount: string;
  remark: string;
  is_multi_order: boolean;
  is_sub_order: boolean;
  type: "merchant" | "merchant";
  user: number;
  deliver: number;
  parent: null;
  payment: null;
  express: null;
};

export default MerchantAgentApi;
